<?php
class AnalyticsController{
	protected $path;	

	function __construct(){		
		global $parameters;	
		// sciezka do folderu
		$domena = str_replace('www.','',$_SERVER['HTTP_HOST'])."/Analytics/";
		tools::_add_folder($parameters['analytics']['host'].$domena);	
		$this->path = 	$parameters['analytics']['host'].$domena.'kod.txt';	
	}
	
	/**
	 * otwiera plik z kodem analytics dla domeny
	 * jesli go nie ma zakłada pusty plik
	 */
	public function indexAction(){
		global $objSession;
		if(is_file($this->path)){	
			$fh = fopen($this->path, 'r+');
			$size = filesize($this->path);
			if ($size != 0) $kod = fread($fh,$size);
		}else{
			$fh = fopen($this->path, 'a+');
			$kod = '';
		}
		fclose($fh);
		$kod = stripcslashes($kod);
		if ( $objSession->IsLoggedIn()  && $objSession->GetUserData("stanowisko") == 'a'){
			tools::_assign('kod',$kod);
			tools::_display('section/const_fotter_analytics_form.tpl');	
		}	
	}

	
	/**
	 * otwiera plik z kodem analytics dla domeny
	 * jesli go nie ma zakłada pusty plik
	 */
	public function showAction(){
		if(is_file($this->path)){	
			$fh = fopen($this->path, 'r+');
			$size = filesize($this->path);
			if ($size != 0) $kod = fread($fh,$size);
		}else{
			$fh = fopen($this->path, 'a+');
			$kod = '';
		}
		fclose($fh);
		echo $kod = stripcslashes($kod);;
	}
	
	public function saveKodAction(){
		global $config,$objSession;
		if ( $objSession->IsLoggedIn()  && $objSession->GetUserData("stanowisko") == 'a'){
			$log = new Logs_Logs($this->path);
			$log->add($config->kod);
		}
	}
}
?>